package com.googlecode.wmlynar.javadoctc.domain;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

/**
 * Stores list of classes documented with javadoc. Allows to retrieve a class
 * object by name.
 *
 * @author Wojciech Mlynarczyk (woj)
 *
 */
public class JavaDocClassPool {

	private ArrayList<JavaDocClass> classes = new ArrayList<JavaDocClass>();
	private HashMap<String, JavaDocClass> classMap = new HashMap<String, JavaDocClass>();

	/**
	 * Adds a class to list of classes.
	 */
	public void addClass(JavaDocClass clas) {
		classes.add(clas);
		classMap.put(clas.getName(), clas);
	}

    /**
     * Adds a method to a class (referenced by name) and if class does not exist it creates it and adds it.
     */
	public void addMethodToClass(String name, JavaDocMethod method) {
		JavaDocClass clas = getClassByName(name);
		if(clas==null) {
			clas = new JavaDocClass(name);
			addClass(clas);
		}
		clas.addMethod(method);
	}


	public List<JavaDocClass> getClassList() {
		return Collections.unmodifiableList(classes);
	}

	public JavaDocClass getClassByName(String name) {
		return classMap.get(name);
	}

}
